package com.tonglin.springboot.service;

//

import com.tonglin.springboot.mapper.BookOrderMapper;
import com.tonglin.springboot.mapper.UserMapper;
import com.tonglin.springboot.po.BookOrder;
import com.tonglin.springboot.po.Status;
import com.tonglin.springboot.po.Status01;
import com.tonglin.springboot.po.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/***
 *
 * 判断数据
 *
 * 返回状态
 *
 *
 */

@Service
public class LoginService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    BookOrderMapper bookOrderMapper;

    Status status = new Status();

    public Status login(String userName, String passWord) {


        //1.判断用户名或者密码是否为空

        if (StringUtils.isBlank(userName) || StringUtils.isBlank(passWord)) {
            status.setCode(false);
            status.setMsg("用户名或者密码不能为空！");
            return status;
        }


        User user = userMapper.queryUserByname(userName);

        if (user == null) {

            status.setCode(false);
            status.setMsg("用户名不存在！请重新输入！");
            return status;
        }
        System.out.println(user.getUserPSW());
        if (!passWord.equals(user.getUserPSW())) {
            status.setCode(false);
            status.setMsg("用户密码错误！");
            return status;
        }


        status.setCode(true);
        status.setMsg("用户登录成功！");

        return status;

    }

    /**
     * 在登录成功页面中显示所借过的书
     * <p>
     * 从订单表中进行操作，查出借过的书，根据用户名来查找
     */

    public List<String> orderInfo(String userName) {

        Status01 status01 = new Status01();
        List<String> list = bookOrderMapper.queryBookOrderByUsername(userName);



     return list;

    }
}
